home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / comm / brc_asp1.zip / ZIPDATE.PAS < prev    next >
Pascal/Delphi Source File  |  1992-01-30  |  5KB  |  98 lines

  1. program ZipDate; {change the date/time of ZIP files to the
  2.                           latest date/time of any file within}
  3. uses
  4.    dos, ZipDir; {I got the ZipDir unit from the Atkinson Home Computer BBS}
  5.                 {I hope I am not violating anyone by including it here}
  6.  
  7. { This program was written by Bruce Clawson, Wauwatosa, WI  USA.
  8.   The unit 'ZIPDIR.PAS' was picked up from the Atkinson Home Computer BBS
  9.   some time ago.  As I can't find any docs for it I sincerely hope that
  10.   I am not violating anyone's rights by including it here.
  11.   My program (ZIPDATE.PAS) is released to the public domain.  You are
  12.   free to use/abuse/modify/distribute it as you wish but please leave
  13.   this comment area intact.  Direct comments to me on EXEC-PC.          }
  14.           { compiled with Borland's Turbo Pascal 6.0 }
  15.  
  16. procedure DateFixer (NameParam : pathstr);
  17. var
  18.    ZipFile      : text;      {the ZIP file itself}
  19.    Drect        : SearchRec; {defined in DOS unit}
  20.    ZipDirect    : DirStr;    {defined in DOS unit}
  21.    ZipName      : NameStr;   {defined in DOS unit}
  22.    ZipExt       : ExtStr;    {defined in DOS unit}
  23.    FullPathName : string;    {used to construct a fully qualified name}
  24.    ZipDirItem   : string;    {ZIP directory item from 'ZIPDIR' unit}
  25.    ZfDaTi       : longint;   {file date/time in system format}
  26.    ZfDateTime   : DateTime;  {file date/time structure (DOS unit)}
  27.    ZipDateTime  : string;    {used to find newest member file}
  28.    TmpDateTime  : string;    {used to find newest member file}
  29.    ZipDirStatus : integer;   {status returned by 'ZIPDIR' unit}
  30.    ErrCode      : integer;   {'val' Error Code}
  31.    Counter      : byte;      {what it says}
  32. begin
  33.    for Counter := 1 to length (NameParam) do   {convert to upper case}
  34.       NameParam [Counter] := upcase (NameParam [Counter]);
  35.    fsplit (NameParam, ZipDirect, ZipName, ZipExt);  {split up}
  36.    if ZipExt <> '.ZIP'                          {we want ZIP files only}
  37.       then exit;
  38.    FindFirst (NameParam, Archive, Drect); {find the first file matching the mask}
  39.    while DosError = 0 do
  40.       begin
  41.       FullPathName := ZipDirect + Drect.Name;  {fully qualified name}
  42.       assign (ZipFile,FullPathName);      {assign the ZIP file}
  43.       reset  (ZipFile);                   {open for input}
  44.       getftime (ZipFile,ZfDaTi);          {get its date/time}
  45.       unpacktime (ZfDaTi, ZfDateTime);    {convert to usable format}
  46.       ZipDateTime := '00000000000000';    {clear out}
  47.       ZipDirSetup (FullPathName,ZipDirStatus); {do ZIP directory setup}
  48.       while ZipDirStatus = 0 do           {until 'eof'}
  49.             begin
  50.             ZipDirFetch (ZipDirItem,ZipDirStatus);  {get ZIP member file info}
  51.             TmpDateTime := copy (ZipDirItem,35,4)   {year}
  52.                          + copy (ZipDirItem,29,2)   {month}
  53.                          + copy (ZipDirItem,32,2)   {day}
  54.                          + copy (ZipDirItem,40,2)   {hour}
  55.                          + copy (ZipDirItem,43,2)   {minute}
  56.                          + copy (ZipDirItem,46,2);  {second}
  57.             if TmpDateTime > ZipDateTime            {which is later?}
  58.                then ZipDateTime := TmpDateTime;
  59.             end;
  60.       with ZfDateTime do       {plug back into DOS.DateTime format}
  61.          begin
  62.          val (copy (ZipDateTime, 1,4),Year, ErrCode);
  63.          val (copy (ZipDateTime, 5,2),Month,ErrCode);
  64.          val (copy (ZipDateTime, 7,2),Day,  ErrCode);
  65.          val (copy (ZipDateTime, 9,2),Hour, ErrCode);
  66.          val (copy (ZipDateTime,11,2),Min,  ErrCode);
  67.          val (copy (ZipDateTime,13,2),Sec,  ErrCode);
  68.          end;
  69.       packtime (ZfDateTime,ZfDaTi);    {convert to system format}
  70.       setftime (ZipFile,ZfDaTi);       {update disk directory values}
  71.       close    (ZipFile);              {close the file}
  72.       writeln;
  73.       write   (FullPathName, '   ');          {show it on the screen}
  74.       write   (copy (ZipDateTime,5,2), '-');
  75.       write   (copy (ZipDateTime,7,2), '-');
  76.       writeln (copy (ZipDateTime,3,2));
  77.       FindNext (Drect);                       {look for another file}
  78.       end;                             {while DosError = 0}
  79. end;                                   {DateFixer}
  80.  
  81. {*********************************}
  82. {-----MAINLINE PROGRAM CODING-----}
  83. {*********************************}
  84. var
  85.    Count   : word;
  86.    CurrDir : string;
  87. begin                                  {MainProgram}
  88.    if ParamCount = 0                   {if no command line parameters}
  89.       then begin
  90.            getdir (0, CurrDir);        {use current dirve:\directory}
  91.            if CurrDir [length (CurrDir)] <> '\'  
  92.               then CurrDir := CurrDir + '\';     {append a '\' if needed}
  93.            DateFixer (CurrDir + '*.ZIP');        {look for ZIP files}
  94.            end
  95.       else for Count := 1 to ParamCount do
  96.               DateFixer (ParamStr (Count));  {use command line parameters}
  97. end.                                   {MainProgram}
  98.